Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds inactive state to ActionList items #3913

Merged
merged 35 commits into from
Dec 11, 2023
Merged

Conversation

mperrotti
Copy link
Contributor

@mperrotti mperrotti commented Nov 6, 2023

Relates to https://github.com/github/primer/issues/2677

Screenshots

InactiveExample-InactiveItem.mp4
Screenshot 2023-11-09 at 4 53 35 PM Screenshot 2023-11-06 at 5 07 22 PM Screenshot 2023-11-17 at 4 09 04 PM

Changelog

Supports inactive ActionList items by letting users pass the required message to the inactiveText prop

New

inactiveText prop on ActionList.Item

Changed

Removed

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan

Testing & Reviewing

  • Check out the new stories for ActionList, ActionMenu, and NavList that demonstrate inactive list items

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews (Storybook)
  • [?] Changes are SSR compatible
    • Not sure. I thought none of our ActionList stuff was SSR compatible due to our use of slots
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge
  • Integration tests pass at github/github (Learn more about how to run integration tests)

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

makes unavailable message consistent

fixes LinkItem styling
@mperrotti mperrotti requested review from a team and joshblack November 6, 2023 22:17
Copy link

changeset-bot bot commented Nov 6, 2023

🦋 Changeset detected

Latest commit: 9ef7b72

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Nov 6, 2023

Uh oh! @mperrotti, the image you shared is missing helpful alt text. Check your pull request body.

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

Copy link
Contributor

github-actions bot commented Nov 6, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 105.42 KB (+0.23% 🔺)
dist/browser.umd.js 105.99 KB (+0.25% 🔺)

@github-actions github-actions bot temporarily deployed to storybook-preview-3913 November 6, 2023 22:22 Inactive
)

const keyPressHandler = React.useCallback(
(event: React.KeyboardEvent<HTMLLIElement>) => {
if (disabled) return
if (disabled || inactive) return
Copy link
Contributor Author

@mperrotti mperrotti Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not calling any handlers passed to onSelect for inactive items. This would also make it impossible to render a dialog when the user clicks the item. I think this is a reasonable limitation to begin with, and we can always update the implementation to support click/selection handlers so users can show a Dialog if we find we need to.

Do you agree that it's safe to prohibit onSelect on inactive items for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a draft PR to update the interface guidelines: primer/design#654

I'll close it if we think we do need to support click/selection behavior on inactive items.
I'll merge it if we don't think we need to support click/selection behavior on inactive items.

import Box, {BoxProps} from '../Box'
import {Tooltip} from '../drafts'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using the new, accessible Tooltip. Is this safe to use even though it's still in the experimental phase?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@broccolinisoup broccolinisoup Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of using the new draft Tooltip, I think it is safe. It is unlikely to have API changes but still possible since it is in the experimental stage. The only API surface that is exposed in Actionlist API I see is the type of the text. Currently text is string and undefined type and I would say it is unlikely that it will change.

On the other hand, tooltip is still going through the accessibility sign-off review but compared to the stable one it solves multiple problems and it is more accessible. I think trying out the new tooltip in Primer rather than dotcom first seems like a good idea to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted a comment/question about the usage as well #3913 (comment) - very keen to hear what you think!

import Box, {BoxProps} from '../Box'
import {Tooltip} from '../drafts'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I try and run tests locally and import the "new" Tooltip, I got this mysterious error:

 FAIL  src/ActionList/ActionList.test.tsx
  ● Test suite failed to run

    TypeError: Cannot read properties of undefined (reading 'LeadingVisual')

      226 | export type NavListLeadingVisualProps = ActionListLeadingVisualProps
      227 |
    > 228 | const LeadingVisual = ActionList.LeadingVisual
          |                                  ^
      229 |
      230 | LeadingVisual.displayName = 'NavList.LeadingVisual'
      231 |

      at Object.LeadingVisual (src/NavList/NavList.tsx:228:34)
      at Object.require (src/NavList/index.ts:1:1)
      at Object.require (src/drafts/index.ts:51:1)
      at Object.require (src/ActionList/Item.tsx:18:1)
      at Object.require (src/ActionList/index.ts:3:1)
      at Object.require (src/index.ts:49:1)
      at Object.require (src/utils/testing.tsx:7:1)
      at Object.require (src/utils/test-matchers.tsx:7:1)

Any idea what might be causing this? I couldn't figure it out.

{
// If it's inactive and isn't rendered in a container like ActionMenu or SelectPanel, render a leading visual with a tooltip
inactive && container === undefined ? (
<Tooltip text={inactiveText}>
Copy link
Member

@siddharthkp siddharthkp Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cursor is on the entire disabled item, should the tooltip also be on the whole item or just the icon?

inactive-item.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the icon

@siddharthkp
Copy link
Member

siddharthkp commented Nov 7, 2023

What is the overlap with disabled state?

<ActionList.Item disabled={true}>: https://primer.style/react/storybook/?path=/story/components-actionlist-features--disabled-item

As far as I remember, disabled was added for exactly this use case. Example of disabled ActionList.Item used with Tooltip

@siddharthkp
Copy link
Member

siddharthkp commented Nov 7, 2023

Just to confirm, I see in ActionList, we always add an alert icon. But in ActionMenu, we only add an alert icon if there is already a leading visual. Is that intentional?

ActionList:
ActionList: always add alert icon

ActionMenu:
ActionMenu: alert icon replaces leading visual if present

Side note: When the other items don't have icons, the alert icon moves the position of the label. Should we try to keep the labels aligned? For example, by using trailingVisual for alert instead of leading?

@mperrotti
Copy link
Contributor Author

What is the overlap with disabled state?

Disabled items don't need to meet the minimum contrast and don't need a message explaining why it's disabled. cc @alexislucio

@mperrotti
Copy link
Contributor Author

Just to confirm, I see in ActionList, we always add an alert icon. But in ActionMenu, we only add an alert icon if there is already a leading visual. Is that intentional?

ActionMenu actually doesn't need to show the alert icon at all since we show the message inline. I just kept it as another visual signal that the item doesn't work. I could easily change it so that ActionMenu items never render the alert icon. What do you think?

@mperrotti
Copy link
Contributor Author

When the other items don't have icons, the alert icon moves the position of the label. Should we try to keep the labels aligned? For example, by using trailingVisual for alert instead of leading?

This is such a rare state that I didn't think we need to worry about the alignment as much as we do for things like single select.

However, I like your idea about using the trailing visual slot. Let me play with it and see how it feels.

@siddharthkp
Copy link
Member

siddharthkp commented Nov 7, 2023

Disabled items don't need to meet the minimum contrast and don't need a message explaining why it's disabled

Is there a use case for disabled items with low contrast that's not covered by inactive? 🤔

ActionMenu actually doesn't need to show the alert icon at all since we show the message inline. I just kept it as another visual signal that the item doesn't work.

Fair enough!

@mperrotti
Copy link
Contributor Author

Is there a use case for disabled items with low contrast that's not covered by inactive? 🤔

If it's disabled and doesn't need to be conveyed to screen reader users. @alexislucio or somebody from a11y could probably give a more detailed answer. We have some info in the interface guidelines: https://primer.style/components/action-list#tooltips-and-dialogs-on-inactive-items

@mperrotti
Copy link
Contributor Author

I took the suggestion to render the inactive indicator in the trailing visual slot to preserve the alignment. Good call @siddharthkp !

@github-actions github-actions bot temporarily deployed to storybook-preview-3913 December 7, 2023 18:54 Inactive
@@ -52,18 +58,21 @@ type MenuItemProps = {
'aria-labelledby'?: string
'aria-describedby'?: string
role?: string
'data-inactive'?: string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be a prop. We set this based on inactiveText value right?

</ActionMenu>
)

// TODO: Uncomment this story when we have inactive buttons
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since inactive buttons have been merged this can be uncommented?

Copy link
Collaborator

@pksjce pksjce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the prompt replies @mperrotti!
Left a couple of comments mainly

  1. data-inactive does not need to be a prop

Would be great to see the following in a follow-up PR

  • Uncomment the story with the inactiveButton
  • Add more comprehensive documentation for inactiveText ie
    • Its shown as tooltip on icon in ActionList and as description in ActionMenu
    • It replaces LeadingVisual if one is already present and adds/replaces TrailingVisual if not. I feel this will be a bit of a surprise to consumers otherwise.
    • In case of a link item, it behaves in a completely different manner.

Also look forward to the Tooltip related future bugfix that is independent of this PR.

Other than that this looks good to me. I will also close out the associated discussion with a few comments for posterity. Thanks for all your efforts!

@mperrotti
Copy link
Contributor Author

In case of a link item, it behaves in a completely different manner.

I'm not sure what you mean about the behavior being completely different on link items.

Copy link
Member

@broccolinisoup broccolinisoup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tooltip usage is looking good! ✨

@mperrotti mperrotti added this pull request to the merge queue Dec 11, 2023
@mperrotti mperrotti removed this pull request from the merge queue due to a manual request Dec 11, 2023
@mperrotti mperrotti added this pull request to the merge queue Dec 11, 2023
Merged via the queue into main with commit cf22577 Dec 11, 2023
29 checks passed
@mperrotti mperrotti deleted the mp/inactive-actionlist-item branch December 11, 2023 22:27
@primer primer bot mentioned this pull request Dec 11, 2023
@primer primer bot mentioned this pull request Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants